#include <gnome.h>

#define WIDTH 400
#define HEIGHT 300

typedef struct{
	gint idx;
	GtkWidget *fixed;
	GtkWidget *button;
}move_t,*pmove_t;

void cb_click(GtkWidget *self,pmove_t pmv){
	//g_print("w:%d , h:%d\n",pmv->button->width_request,0);
	GtkAllocation rect;
	//gtk_widget_get_clip(pmv->button,&allocation);
	gtk_widget_get_allocation(pmv->button,&rect);
	g_print("[%d,%d] w:%d h:%d\n",rect.x,rect.y,rect.width,rect.height);

	gint x = random() % (WIDTH - rect.width);
	gint y = random() % (HEIGHT - rect.height);
	gchar * str = g_strdup_printf("#%d(%d,%d)",pmv->idx,x,y);
	gtk_button_set_label(GTK_BUTTON(pmv->button),str);
	gtk_fixed_move(GTK_FIXED(pmv->fixed),pmv->button,x,y);
}

GtkWidget *make_fixed_container(void){
	GtkWidget *fixed = gtk_fixed_new();
	static move_t mvs[3];
	for(int i = 0;i < 3;i++){
		mvs[i].idx = i;
		mvs[i].fixed = fixed;
		mvs[i].button = gtk_button_new_with_label(g_strdup_printf("#%d(100,100)",i));
		gtk_signal_connect(GTK_OBJECT(mvs[i].button),"clicked",
			GTK_SIGNAL_FUNC(cb_click),&mvs[i]);
		gtk_fixed_put(GTK_FIXED(fixed),mvs[i].button,100,100);
	}
	return fixed;
}

int main(int argc,char *argv[]){
	GtkWidget *w;
	GtkWidget *fixed;

	srandom(time(NULL));

	gnome_init("","",argc,argv);
	w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_default_size(GTK_WINDOW(w),WIDTH,HEIGHT);
	gtk_signal_connect(GTK_OBJECT(w),"destroy",G_CALLBACK(gtk_main_quit),NULL);
	fixed = make_fixed_container();
	gtk_container_add(GTK_CONTAINER(w),fixed);
	gtk_widget_show_all(w);
	gtk_main();
	return 0;
}